package com.xinsoft.controller.device;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.CusDeviceCapacityPageParam;
import com.xinsoft.entity.po.CusDeviceCapacity;
import com.xinsoft.service.CusDeviceCapacityService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cus/deviceCapacity")
public class CusDeviceCapacityController {

    @Autowired
    private CusDeviceCapacityService cusDeviceCapacityService;

    /**
     * 新增
     */
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> add(@RequestBody CusDeviceCapacity cusDeviceCapacity) {
        // 参数校验
        ValidatorUtils.validateEntity(cusDeviceCapacity);
        return Response.succeed(cusDeviceCapacityService.addCusDeviceCapacity(cusDeviceCapacity));
    }

    /**
     * 更新
     */
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> edit(@RequestBody  CusDeviceCapacity cusDeviceCapacity) {
        // 参数校验
        ValidatorUtils.validateEntity(cusDeviceCapacity);
        return Response.succeed(cusDeviceCapacityService.editCusDeviceCapacity(cusDeviceCapacity));
    }

    /**
     * 获取详情
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(cusDeviceCapacityService.getCusDeviceCapacity(id));
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> del(@RequestBody List<Integer> ids) {
        cusDeviceCapacityService.del(ids);
        return Response.succeed();
    }


    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody CusDeviceCapacityPageParam cusDeviceCapacityPageParam) {
        return Response.succeed(cusDeviceCapacityService.findPageListByParam(cusDeviceCapacityPageParam));
    }
}
